import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/dashboard'
    },
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/Dashboard.vue'),
      meta: {
        title: '仪表板',
        icon: 'Monitor'
      }
    },
    {
      path: '/kv-manager',
      name: 'KvManager',
      component: () => import('@/views/kv-manager/KvManager.vue'),
      meta: {
        title: 'KV管理',
        icon: 'Key'
      }
    },
    {
      path: '/batch-operations',
      name: 'BatchOperations',
      component: () => import('@/views/batch-operations/BatchOperations.vue'),
      meta: {
        title: '批量操作',
        icon: 'Operation'
      }
    },
    {
      path: '/statistics',
      name: 'Statistics',
      component: () => import('@/views/statistics/Statistics.vue'),
      meta: {
        title: '统计分析',
        icon: 'TrendCharts'
      }
    }
  ]
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - 分布式KV服务`
  }
  next()
})

export default router